{extend name="public/layout"}
{block name="content"}
<div class="layui-col-md12">
    <div class="layui-card">

        <div class="layui-card-header">
            <button class="layui-btn" onclick="xadmin.open('添加用户组','{:admin_url('role/add')}')">添加用户组</button>
        </div>
        <div class="layui-card-body ">
            <table class="layui-table layui-form">
              <thead>
                <tr>
                  <!-- <th>
                    <input type="checkbox" name=""  lay-skin="primary">
                  </th> -->
                  <th>ID</th>
                  <th>名称</th>
                  <th>描述</th>
                  <th>操作</th></tr>
              </thead>
              <tbody>
                {volist name="datalist" id="vo"}
                <tr>
                  <!-- <td>
                    <input type="checkbox" name=""  lay-skin="primary"> 
                  </td> -->
                  <td>{$vo['id']}</td>
                  <td>{$vo['title']}</td>
                  <td>{$vo['desc']}</td>
                  <td class="td-manage">
                        <button type="button" data-url="{:admin_url('role/edit/'.$vo['id'])}" onclick="xadmin.open('编辑用户组',this.dataset.url)" class="layui-btn ">编辑</button>
                        <button data-url="{:admin_url('role/delete/'.$vo['id'])}" type="button" class="layui-btn layui-btn-danger delete-btn">删除</button>
                  </td>
                </tr>
                {/volist}
              </tbody>
            </table>
        </div>
    </div>
</div>
{/block}

{block name="foot"}
<script>
(function(){
      $('.layui-table').on('click','.delete-btn',function(){
        var obj = this;
        layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
              console.log(obj.dataset)
              
              var index = layer.load()
              $.ajax({
                'type':'post',
                'url':obj.dataset.url,
                success:function(data){
                  layer.close(index)
                  layer.alert(data.msg||'服务器出现错误',{icon:data.err_code === 200?6:5,end:function(){
                    if(data.err_code === 200){
                      location.reload();
                    }
                  }});
                }
              })
        });
      });
})();

</script>
{/block}